package net.xdclass.base_project.producerConfig;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @author sqz
 * @Description: 自定义分区，消息发送到指定分区
 * @date 2019/9/23 17:20
 */
public class KafkaProducerPartitionConfig implements Partitioner {
    /**
     * 返回值就是指定的分区，可以根据topic,key等等进行hash然后放到指定分区上
     * @param topic
     * @param key
     * @param keyBytes
     * @param value
     * @param valueBytes
     * @param cluster
     * @return
     */
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        return 1;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
